<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-yellow sidebar-mini">
<section class="content-header">
    <h1>排产计划科级审核</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" class="form-horizontal">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        项目编号
                                    </label>
                                    <label class="control-label">
                                        <input name="propProdNo" class="form-control" type="text" maxlength="255"
                                               value=""
                                               placeholder="请输入项目编号"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        项目名称
                                    </label>
                                    <label class="control-label">
                                        <input name="prodName" class="form-control" type="text" maxlength="255"
                                               placeholder="请输入项目名称"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        审核状态
                                    </label>
                                    <label class="control-label">
                                        <select name="propStaStr" class="form-control">
                                            <option value="2,3,4">全部</option>
                                            <option selected="selected" value="2,6">待审核</option>
                                            <option value="3,4,5">已审核</option>
                                        </select>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        分类
                                    </label>
                                    <label class="control-label">
                                        <select name="prodTyp" class="form-control">
                                            <option selected="selected" value="">全部</option>
                                            <option value="1">设备类</option>
                                            <option value="2">其他</option>
                                        </select>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        排产人
                                    </label>
                                    <label class="control-label">
                                        <input name="applicant" list="applicantList" class="form-control"
                                               oninput="loadApplicantList(this)" placeholder="请输入排产人"
                                               autocomplete="off"/>
                                        <datalist id="applicantList">
                                        </datalist>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">交货时间</label>
                                    <label class="control-label">
                                        <input type="text" class="form-control datepicker" name="startTime"
                                               readonly="readonly"/>
                                        <span> 至 </span>
                                        <input type="text" class="form-control datepicker" name="endTime"
                                               readonly="readonly"/></label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">排产日期</label>
                                    <label class="control-label">
                                        <input type="text" class="form-control datepicker" name="startTime2"
                                               readonly="readonly"/>
                                        <span> 至 </span>
                                        <input type="text" class="form-control datepicker" name="endTime2"
                                               readonly="readonly"/></label>
                                </div>
                                <button id="btn-search" type="button" class="btn btn-success">
                                    搜索
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div id="toolbar" class="row">
                    <!--                    <button id="btn_getData" class="btn btn-success">获取数据</button>-->
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    let table, tempTable, tempData = new Array(), currentProject;
    $(function () {
        /**
         * 加载列表
         */
        loadTable();
        /**
         * 表格搜索
         */
        $("#btn-search").click(function () {
            js.table.search(table);
        });
    });

    /**
     * 加载申请人列表
     */
    function loadApplicantList(obj) {
        js.post({
            url: ctx + 'task/loadApplicantList',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {
                name: $(obj).val()
            },
            async: true,                // 异步执行
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    let list = result.data;
                    $("#applicantList").empty();
                    for (let i = 0; i < list.length; i++) {
                        $("#applicantList").append('<option value="' + list[0] + '">' + list[0] + '</option>');
                    }
                }
            },
            error: function () {
                js.modal.fail();
            }
        });
    }

    /**
     * 重新加载
     */
    function reloadTable() {
        js.table.refresh(table);
    }

    /**
     * 加载列表
     */
    function loadTable() {
        table = js.table.init({
            url: ctx + "task/audit/list",
            showColumns: true,
            showExport: true,
            columns: [
                {
                    title: '序号', width: '60',
                    formatter: function (value, row, index, field) {
                        var pageSize = table.bootstrapTable('getOptions').pageSize;
                        var pageNumber = table.bootstrapTable('getOptions').pageNumber;
                        return pageSize * (pageNumber - 1) + index + 1;
                    }
                },
                {
                    title: '项目编号', field: 'propProdNo',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '项目名称', field: 'prodName',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '数量', field: 'propProdNum', width: '60',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '需方', field: 'customer', width: '160',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '安装地点', field: 'insSite', width: '160',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '交货时间', field: 'prodDelDat', width: '90'
                }
                ,
                {
                    title: '是否<br>重点', field: "prodIsKey", width: '50',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            if (parseInt(value) === 1) {
                                return '是';
                            } else {
                                return '否';
                            }
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '分类', field: "prodTyp", width: '50',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            if (parseInt(value) === 1) {
                                return '设备类';
                            } else {
                                return '其他类';
                            }
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '排产人', field: "schNam",
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '排产日期', field: "propCreDat", width: '90',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '审核状态', field: "propSta",
                    formatter: function (value, row, index) {
                        if (value != null) {
                            if (value === 3) {
                                return '<label class="badge label-success">已审核-通过</label>';
                            } else if (value === 4) {
                                return '<label class="badge label-success">已审核-科级驳回</label>';
                            } else if (value === 6) {
                                return '<label class="badge label-danger">待审核-部级驳回</label>';
                            } else if (value === 2) {
                                return '<label class="badge label-default">待审核</label>';
                            }
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '驳回原因',width: '100',
                    formatter: function (value, row, index) {
                        if ((row.propRejReaMin === null && row.propRejReaMin === '') && (row.propRejRea !=null && row.propRejRea !="")) {
                            return "科长驳回原因："+row.propRejRea;
                        }else if (row.propRejReaMin != null && row.propRejReaMin != '' && row.propRejRea !=null && row.propRejRea !='') {
                            return "部长驳回原因："+row.propRejReaMin+"<BR>科长驳回原因："+row.propRejRea;
                        }else if ((row.propRejReaMin != null && row.propRejReaMin != '') && row.propRejRea ===null) {
                            return "部长驳回原因："+row.propRejReaMin;
                        }
                        else {
                            return '--';
                        }
                    }
                },
                {
                    title: '操作', width: '60',
                    formatter: function (value, row, index) {
                        let elements = new Array();
                        if ((row.propSta === 2 || row.propSta === 6) && hasP('pro:proPlanCheck:edit')) {
                            elements.push('<button class="btn btn-warning btn-xs" onclick="audit(' + row.prodId + ')">审核</button>');
                        } else if ((row.propSta === 3 || row.propSta === 4 || row.propSta === 5 || row.propSta === 6) && hasP('pro:proPlanCheck:edit')) {
                            elements.push('<button class="btn btn-info btn-xs" onclick="view(' + row.prodId + ')">查看</button>');
                        }
                        return elements.join('');
                    }
                }
            ]
        });
    }


    /**
     * 跳转到审核总调计划页面
     */
    function audit(propId) {
        window.open(ctx + "task/goto/audit/" + propId);
    }

    /**
     * 跳转到查看总调计划页面
     */
    function view(propId) {
        window.open(ctx + "task/scheduling/see/" + propId);
    }

    /**
     * 重新加载
     */
    function reLoad() {
        js.table.refresh(table);
    }
</script>
</body>
</html>